#ifndef QMEMERYEDITOR_H
#define QMEMERYEDITOR_H

#include "../qbasedialog.h"
#include "../qbaseitemdelegate.h"
#include <QVariant>

#include <QItemDelegate>
#include <QTreeWidgetItem>
#include <QMap>

class QAbstractProperty;

namespace Ui {
class QMemeryEditor;
}

class QMemeryItemDelegate: public QBaseItemDelegate
{
    Q_OBJECT
public:
    QMemeryItemDelegate(QAbstractProperty* property);
    QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void    setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
    void    setEditorData(QWidget *editor, const QModelIndex &index) const;
protected:
    QAbstractProperty   *m_property;
public:
    QMap<QString,QString>   m_property_to_name;
    QMap<QString,QString>   m_name_to_property;
    QMap<QString,QString>   m_data_to_name;
    QMap<QString,QString>   m_name_to_data;
    QStringList             m_property_names;
    QStringList             m_data_names;
};

class QMemeryEditor : public QBaseDialog
{
    Q_OBJECT
    
public:
    explicit QMemeryEditor(QAbstractProperty *property,QWidget *parent = 0);
    ~QMemeryEditor();
    
    QVariant    get_value();
protected:
    bool    eventFilter(QObject *, QEvent *);

    void    tree_widget_menu_event(QContextMenuEvent *e);
    void    tree_widget_double_click(QMouseEvent* e);
protected slots:
    void    add();
    void    del();
private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

private:
    Ui::QMemeryEditor *ui;
    QVariant        m_value;
    QAbstractProperty   *m_property;

    QTreeWidgetItem     *m_click_item;
};

#endif // QMEMERYEDITOR_H
